#include "../Share/ShareMemDB/ShMemDBMgr.h"
#include <iostream>
int main(int argc, t_char* argv[])
{
	ACE_OS::srand((ACE_OS::time(NULL)));

	CShMemDBMgr DBMgr;
	if (DBMgr.BeginService()==-1)
	{
		DBMgr.EndService();
		return -1;
	}

	t_char CTRL[ 128 ];
	while (true)
	{
		std::cin>>CTRL;
		if (ACE_OS::strcmp(CTRL,"quit") == 0)
		{
			DBMgr.EndService();
			break;
		}
		if (ACE_OS::strcmp(CTRL,"f") == 0)
		{
			DataBase* pDB=DBMgr.GetMemDB("a");
			Table* pTable=pDB->GetTable("a");
			FieldInfo info;
			ACE_OS::memset(&info,0,sizeof(info));
			ACE_OS::strncpy(info.szFieldName,"ddd",10);
			info.wSize=4;
			//pTable->PushBackField(&info);

			ACE_OS::memset(&info,0,sizeof(info));
			ACE_OS::strncpy(info.szFieldName,"eee",10);
			info.wSize=4;
			//pTable->PushBackField(&info);
		}
		if (ACE_OS::strcmp(CTRL,"i") == 0)
		{
			DataBase* pDB=DBMgr.GetMemDB("a");
			Table* pTable=pDB->GetTable("a");
			FieldInfo info;
			ACE_OS::memset(&info,0,sizeof(info));
			ACE_OS::strncpy(info.szFieldName,"ffff",10);
			info.wSize=4;
			pTable->InsertField(info,1);
		}
		if (ACE_OS::strcmp(CTRL,"d") == 0)
		{
			DataBase* pDB=DBMgr.GetMemDB("a");
			Table* pTable=pDB->GetTable("a");
			pTable->DeleteField(0);
		}
		if (ACE_OS::strcmp(CTRL,"c") == 0)
		{
			/*DataBase* pDB=DBMgr.GetMemDB("a");

			pDB->CreateTable("a",3);*/
		}
		if (ACE_OS::strcmp(CTRL,"s") == 0)
		{
			DataBase* pDB=DBMgr.GetMemDB("a");
			//Table* pTable=pDB->GetTable("a");
			////Row* pRow=pTable->CreateRow();
			////pTable->GetFieldID("d");
			////int i=345;
			////pTable->SetFieldValue(pRow,0,&i);
			////
			////int* p=(int*)pTable->GetFieldValue(pRow,0);
			////int k=*p;
			////int j=0;
			//ACE_DEBUG ((LM_INFO, ACE_TEXT ("%D:SELECT START\n")));
			//for (int i=0;i<100;i++)
			//{
			//	int k=ACE_OS::rand()%500000;
			//	pTable->FindValue(0,&i);
			//}
			//ACE_DEBUG ((LM_INFO, ACE_TEXT ("%D:SELECT END\n")));
		}
	}
	return 0;
}